package com.d3works.apps.crm.service;

import com.d3works.apps.base.db.Partner;
import com.d3works.apps.crm.db.Event;
import com.d3works.apps.crm.db.EventAttendee;
import com.d3works.apps.crm.db.Lead;

public class EventAttendeeService {

  public EventAttendee createEventAttendee(Event event, Lead lead, Partner contactPartner) {

    EventAttendee eventAttendee = new EventAttendee();
    eventAttendee.setEvent(event);
    eventAttendee.setEventAttendeeLead(lead);
    eventAttendee.setContactPartner(contactPartner);

    eventAttendee.setName(this.getName(eventAttendee));

    return eventAttendee;
  }

  public String getName(EventAttendee eventAttendee) {

    if (eventAttendee.getContactPartner() != null) {
      return eventAttendee.getContactPartner().getFullName();
    }
    if (eventAttendee.getEventAttendeeLead() != null) {
      return eventAttendee.getEventAttendeeLead().getFullName();
    }

    return "";
  }
}
